# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=open-lldp
_realname=lldpad
pkgver=0.9.46
pkgrel=5
pkgdesc="Open Source implementation of the IEEE standard 802.1AB Link Layer Discovery Protocol (LLDP)"
url="http://www.open-lldp.org"
arch="all"
license="GPL-2.0-only"
makedepends="autoconf automake bash flex libtool libconfig-dev libnl-dev
	readline-dev linux-headers bsd-compat-headers"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-bash-completion:bashcomp:noarch
	"
source="http://ftp-osl.osuosl.org/pub/open-lldp/open-lldp-$pkgver.tar.gz
	clif.h.patch
	$pkgname.initd
	$pkgname.confd
	"

prepare() {
	default_prepare
	sed -i 's/ln -T -s/ln -s/' Makefile.am
	sed -i -e 's/-Werror//' Makefile.am configure.ac
	./bootstrap.sh
}

build() {
	export CFLAGS="$CFLAGS -fgnu89-inline"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info
	make
}

package() {
	make DESTDIR="$pkgdir" install
	mkdir -p "$pkgdir"/usr/include/dcbd
	# ln -s /usr/include/lldpad "$pkgdir"/usr/include/dcbd
	ln -s /usr/include/lldpad/lldp_dcbx_cmds.h "$pkgdir"/usr/include/dcbd/clif_cmds.h
	install -m755 -D ../../$pkgname.initd "$pkgdir"/etc/init.d/$_realname
	install -m644 -D ../../$pkgname.confd "$pkgdir"/etc/conf.d/$_realname

	mkdir -p "$pkgdir"/usr/share/bash-completion
	mv "$pkgdir"/etc/bash_completion.d "$pkgdir"/usr/share/bash-completion/completions
}

bashcomp() {
	depends=""
	pkgdesc="Bash completions for $pkgname"
	install_if="$pkgname=$pkgver-r$pkgrel bash-completion"

	amove usr/share/bash-completion/completions
}

sha512sums="45982ba69c159ca386970d49de8cee70b654e762b60d95c96a4794ee696e6c889694bb12eb1454e6c176152c949e67af38974a431838c3788d9bc42751c60878  open-lldp-0.9.46.tar.gz
fd9eca241564e76df2b97d8048b788fc35c3d791a1784386e68bf92dfd39076b356546adee42028007483f0cdb579b0da519d0376791d0f902f7e83df60d9306  clif.h.patch
cfd618d2414ec1624e66105b5357de93414b0320badf63b78cbab9b5bb493bd8ef7cac9a22ba4d60418037d2d6636469a20dc288906348c2332beb786f67f808  open-lldp.initd
8f8a68b9764e3b2be0cc01a37debb099e3d9021c354eb8d584a5123c470002f1f61ecc5688e5d958c8c576fd36df7a65233192221849a8fc51e999a7c5ea5678  open-lldp.confd"
